<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/validationEngine/css/validationEngine.jquery.css" />
<div id="content">
    <div id="left">
        <?php
        $this->widget ( 'application.modules.manage.widgets.ViewWidgets', array (
            'view' => 'nav_contentmore'
        ) );
        ?>
    </div>
    <div id="right">
        <div class="box">
            <div class="title">
                <h5>内容管理>图片编辑</h5>
            </div>
            <div class="viewbar tar ptr10">
                <button class="btn" onclick="save()">保存</button>
            </div>

            <div class="form" >
                <form name="form_edit" id="form_edit" action="edit" method="post" >
                    <input type="hidden" name="image_id" value="<?php echo $id; ?>" />
                    <input type="hidden" name="current" value="<?php echo $current; ?>" />
                    <table class="form">
                        <tr>
                            <td class="label">模块</td>
                            <td>
                                <select class="small" name="module_id" id="module_id">
                                    <?php
                                    foreach($module as $m){
                                        if($image['module_id'] == $m['module_id']){
                                            ?>
                                            <option value="<?php echo $m['module_id']; ?>" selected="selected"><?php echo $m['category']; ?></option>
                                        <?php
                                        }else{
                                            ?>
                                            <option value="<?php echo $m['module_id']; ?>"><?php echo $m['category']; ?></option>
                                        <?php
                                        }
                                    }
                                    ?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">标题</td>
                            <td><input type="text" class="small validate[required] " name="title" value="<?php echo $image['title']; ?>" />&nbsp;&nbsp;<span class="red">*</span></td>
                        </tr>
                        <tr>
                            <td class="label">图片</td>
                            <td><input type="text" class="small " name="image" value="<?php echo $image['image']; ?>" />
                                &nbsp;&nbsp;<button class="btn" id="imageselect">选择图片</button>&nbsp;&nbsp;<button class="btn"  onclick="viewImg()">预览</button>&nbsp;&nbsp;<span class="red">*</span>
                                <div class="hid"><a id="prviewimg" href="<?php echo $image['image']?>"><img id="imgprviewimg" src=""/></a>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <textarea name="description" style="width:100%;height:250px;">
                                    <?php echo $image['description']; ?>
                                </textarea>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">排序</td>
                            <td>
                                <?php
                                if($id == 0){
                                    ?>
                                    <input type="text" class="small validate[required,custom[integer]] " name="orderby" value="0"  />
                                    <?php
                                }else{
                                    ?>
                                    <input type="text" class="small validate[required,custom[integer]] " name="orderby" value="<?php echo $image['orderby'] ?>"  />
                                    <?php
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">标签</td>
                            <td><input type="text" class="small" name="tags" value="<?php echo $tagstr; ?>" />&nbsp;&nbsp;标签之间使用,分开</td>
                        </tr>
                    </table>
                </form>
            </div>

        </div>
    </div>
</div>
<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/kindeditor/themes/default/default.css" />
<script src="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/kindeditor/lang/zh_CN.js"></script>
<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/fancybox/jquery.fancybox-1.3.4.css" />
<script charset="utf-8" src="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/fancybox/jquery.fancybox-1.3.4.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/validationEngine/jquery.validationEngine.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl?>/css/manage/plugins/validationEngine/jquery.validationEngine-zh_CN.js"></script>
<script>
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="description"]', {
            items:editoritem_more,
            resizeType:1,
            allowFileManager : true,
            uploadJson:'<?php echo Yii::app()->request->baseUrl?>/extra/kindeditor/upload_json.php',
            fileManagerJson:'<?php echo Yii::app()->request->baseUrl?>/extra/kindeditor/file_manager_json.php'
        });

        var imageeditor = K.editor({
            allowFileManager : true,
            fileManagerJson:'<?php echo Yii::app()->request->baseUrl?>/extra/kindeditor/file_manager_json.php',
            uploadJson:'<?php echo Yii::app()->request->baseUrl?>/extra/kindeditor/upload_json.php'
        });
        K('#imageselect').click(function() {
            imageeditor.loadPlugin('image', function() {
                imageeditor.plugin.imageDialog({
                    imageUrl : $("input[name=image]").val(),
                    clickFn : function(url, title, width, height, border, align) {
                        $("input[name=image]").val(url);
                        $("#prviewimg").attr("href",url);
                        $("a#prviewimg").fancybox();
                        imageeditor.hideDialog();
                    }
                });
            });
        });

        $("a#prviewimg").fancybox();

    });



    function save(){
        if($("select[name=module_id]").val()==undefined){
            $('#module_id').validationEngine('showPrompt', '模块不能为空', 'error', true)
            return;
        }
        if($("#form_edit").validationEngine('validate')){
            editor.sync();
            var description = editor.html();;
            if(description.length>0){
                document.forms['form_edit'].submit();
            }else{
                alert('描述至少需要100字');
            }
        }
    }
    function viewImg(){
        var image = $("input[name=image]").val();
        if(!isNull(image)){
            $("a#prviewimg").trigger("click");
        }else{
            alert("图片不能为空");
        }
    }
</script>